package com.exigenservices.practice.roadcompanion.service;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created with IntelliJ IDEA.
 * User: Konstantin
 * Date: 17.07.13
 * Time: 16:44
 * To change this template use File | Settings | File Templates.
 */
public class Hash {

    public static String getHash(String text){
        MessageDigest md5;
        StringBuffer hexString = new StringBuffer();

        try{
            md5 = MessageDigest.getInstance("md5");

            md5.reset();
            md5.update(text.getBytes());

            byte messageDigest[] = md5.digest();

            for(int i = 0; i < messageDigest.length; i++){
                hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
            }

        } catch (NoSuchAlgorithmException ex){
            return ex.getMessage();
        }

        return hexString.toString();
    }
}
